#include "RingQueue.hpp"
#include <unistd.h>

void* consumer(void* args)
{
    sleep(1);
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    while(true)
    {
        int data = 0;
        rq->Pop(&data);
        std::cout << "消费者消费了一个数据：" << data << std::endl;
    }
}

void* productor(void* args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int>*>(args);
    int data = 0;
    while(true)
    {
        rq->EnQueue(data);
        std::cout << "生产者生产了一个数据：" << data++ << std::endl;
    }
}

int main()
{
    pthread_t c[2], p[3];
    RingQueue<int>* rq = new RingQueue<int>();
    pthread_create(c, nullptr, consumer, (void*)rq);
    pthread_create(c+1, nullptr, consumer, (void*)rq);
    pthread_create(p, nullptr, productor, (void*)rq);
    pthread_create(p+1, nullptr, productor, (void*)rq);
    pthread_create(p+2, nullptr, productor, (void*)rq);


    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(p[2], nullptr);

    delete rq;


    return 0;
}